Xbasic

SQL::ConnectionToCSV Method

Syntax

dim result as C = ToCSV(SQLStatement as C [, Arguments as SQL::Arguments] [, IncludeHeaderRow as L = .f. [, RowsToCopy as N = -1[, StartRow as N = -1 [, UpperCaseNames as L = .f. [, DateTimeFormat as C = "" [, DateFormat as C = "" [, TextToSubstituteForBinary as C = "<Binary Data>"]]]]]]]])

Arguments

SQLStatementCharacter

A SQL SELECT statement.

ArgumentsSQL::Arguments

Default = null_value(). A SQL::Arguments object. One or more arguments to be resolved when the SELECT statement is executed.

IncludeHeaderRowLogical

Default = .f.. If true, the first row in the result will be the column names.

RowsToCopyNumeric

Default = -1 (copy all rows). The number of rows to copy.

StartRowNumeric

Default = -1 (start with next row in the result set). The starting row.

UpperCaseNamesLogical

Default = .f.. If true and the header row is included, the header row column names will be converted to uppercase.

DateTimeFormatCharacter

Default = "". The date time format used to format date time fields in the CSV data. See Date and Time Format Elements for more information about date time formats.

DateFormatCharacter

Default = "". The date format used to format date fields in the CSV data. See Date and Time Format Elements for more information about date formats.

TextToSubstituteForBinaryCharacter

Default = "<Binary Data>". A text string used in place of binary data in the CSV data.

Returns

resultCharacter

Returns the result set in CSV (comma separated variable) format.

Description

Fetch data using a SQL query and return the data formatted as a CSV string.

Discussion

This function is useful in displaying the result of a query against a database. For example, after opening a database, like Northwind, you can use the [Execute()] function to perform a query. You can then use the toCSV() function to delimitate all of the results from the query using a comma.

Example

dim cn as SQL::Connection
cn.open("::Name::AADemo-Northwind")

dim sql as c = "select FIRST 5 * from orders"

?cn.toCSV(sql)
= 10248,VINET,5,07/04/1996 00:00:00.000,08/01/1996 00:00:00.000,07/16/1996 00:00:00.000,3,32.38,Vins et alcools Chevalier,59 rue de l'Abbaye,Reims,,51100,France
10249,TOMSP,6,07/05/1996 00:00:00.000,08/16/1996 00:00:00.000,07/10/1996 00:00:00.000,1,11.61,Toms Spezialitäten,Luisenstr. 48,Münster,,44087,Germany
10250,HANAR,4,07/08/1996 00:00:00.000,08/05/1996 00:00:00.000,07/12/1996 00:00:00.000,2,65.83,Hanari Carnes,"Rua do Paço, 67",Rio de Janeiro,RJ,05454-876,Brazil
10251,VICTE,3,07/08/1996 00:00:00.000,08/05/1996 00:00:00.000,07/15/1996 00:00:00.000,1,41.34,Victuailles en stock,"2, rue du Commerce",Lyon,,69004,France
10252,SUPRD,4,07/09/1996 00:00:00.000,08/06/1996 00:00:00.000,07/11/1996 00:00:00.000,2,51.3,Suprêmes délices,"Boulevard Tirou, 255",Charleroi,,B-6000,Belgium